package com.stream.demo2;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.stream.demo1.Foo;

public class ReduceTest2 {
	
	public static void main(String[] args) {
		List<Testa> testaList = new ArrayList<>();
		Testa ta1 = new Testa("aa", "aa1", "aa11");
		Testa ta2 = new Testa("aa1", "aa2", "aa11");
		Testa ta3 = new Testa("aa", "aa3", "aa11");
		Testa ta4 = new Testa("aa1", "aa4", "aa11");
		Testa ta5 = new Testa("aa1", "aa5", "aa11");
		Testa ta6 = new Testa("aa2", "aa6", "aa11");
		testaList.add(ta1);
		testaList.add(ta2);
		testaList.add(ta3);
		testaList.add(ta4);
		testaList.add(ta5);
		testaList.add(ta6);
		
		List<Testb> testbList = new ArrayList<>();
		
		testaList.stream().collect(Collectors.groupingBy(Testa::getName1,Collectors.toList()))
//		.forEach((name,fooListByName) -> {
//			Testb tb = new Testb();
//			tb = fooListByName
//            .stream()
//            .reduce(tb,
//            		(tb0,a)->{
//            	tb0.setName1(a.getName1());
//            	tb0.getList().add(new Testc(a.getName2(), a.getName3()));
//            	return tb0;
//            },(u,t)->{
//            	System.err.println("u:"+u);
//            	System.err.println("t:"+t);
//            	return u;
//            });
//			testbList.add(tb);
//		});
		.forEach((name,fooListByName) -> {
			Testb tb = new Testb();
			tb = fooListByName
					.stream()
					.reduce(tb,
							(tb0,a)->tb0.aad(a),(u,t)->{
								System.err.println("u:"+u);
								System.err.println("t:"+t);
								return u;
							});
			testbList.add(tb);
		});
		
		for(Testb tb:testbList){
			System.out.println("sdf:"+tb.toString());
		}
	}
}
